Spread.Services Documentation
Configure Chart Axis
Spread.Services Documentation > Developer's Guide > Manage Data in Spread Component > Use Chart > Customize Chart Objects > Axis and Other Lines > Configure Chart Axis

In Spread.Services, you can configure chart axis using the following elements in your spreadsheet:

Axis title

While configuring chart axis, you can set the style for the axis title as per your preferences by using the AxisTitle property of the IAxis interface

Refer to the following example code to configure axis title's layout.

C#
Copy Code
IShape shape = worksheet.Shapes.AddChart(ChartType.ColumnClustered, 200, 100, 300, 300);
worksheet.Range["A1:D6"].Value = new object[,]
{
    {null, "S1", "S2", "S3"},
    {"Item1", 10, 25, 25},
    {"Item2", -51, -36, 27},
    {"Item3", 52, -85, -30},
    {"Item4", 22, 65, 65},
    {"Item5", 23, 69, 69}
};
shape.Chart.SeriesCollection.Add(worksheet.Range["A1:D6"], RowCol.Columns, true, true);

IAxis category_axis = shape.Chart.Axes.Item(AxisType.Category);
IAxis value_axis = shape.Chart.Axes.Item(AxisType.Value);
category_axis.HasTitle = true;
category_axis.AxisTitle.Format.Fill.Color.RGB = Color.Pink;
category_axis.AxisTitle.Text = "aaaaaaaaaa";
category_axis.AxisTitle.Font.Size = 20;
category_axis.AxisTitle.Font.Color.RGB = Color.Green;
category_axis.AxisTitle.Font.Strikethrough = true;

Gridlines

While configuring the axis of a chart, you can also set the style of major and minor gridlines as per your choice using the HasMajorGridlines propertyHasMinorGridlines propertyMajorGridlines property and MinorGridlines property of the IAxis interface.

Refer to the following example code to set major and minor gridlines' style.

C#
Copy Code
IShape shape = worksheet.Shapes.AddChart(ChartType.ColumnClustered, 200, 100, 300, 300);
worksheet.Range["A1:D6"].Value = new object[,]
{
    {null, "S1", "S2", "S3"},
    {"Item1", 10, 25, 25},
    {"Item2", -51, -36, 27},
    {"Item3", 52, -85, -30},
    {"Item4", 22, 65, 65},
    {"Item5", 23, 69, 69}
};
shape.Chart.SeriesCollection.Add(worksheet.Range["A1:D6"], RowCol.Columns, true, true);

IAxis value_axis = shape.Chart.Axes.Item(AxisType.Value);
IAxis category_axis = shape.Chart.Axes.Item(AxisType.Category);
category_axis.HasMajorGridlines = true;
category_axis.HasMinorGridlines = true;
category_axis.MajorGridlines.Format.Line.Color.RGB = Color.Red;
category_axis.MajorGridlines.Format.Line.Weight = 3;
category_axis.MinorGridlines.Format.Line.Color.RGB = Color.Green;
category_axis.MinorGridlines.Format.Line.Weight = 1;
category_axis.MinorGridlines.Format.Line.Style = LineStyle.ThickThin;

Display unit label

While configuring the chart axis in your worksheet, you can also set the display unit for the axis and configure its label style using the DisplayUnit property, DisplayUnitLabel property and HasDisplayUnitLabel property of the IAxis interface.

Refer to the following example code to set display unit for the axis and configure its label style.

C#
Copy Code
IShape shape = worksheet.Shapes.AddChart(ChartType.ColumnClustered, 200, 100, 300, 300);
worksheet.Range["A1:D6"].Value = new object[,]
{
    {null, "S1", "S2", "S3"},
    {"Item1", 10, 25, 25},
    {"Item2", -51, -36, 27},
    {"Item3", 52, -85, -30},
    {"Item4", 22, 65, 65},
    {"Item5", 23, 69, 69}
};
shape.Chart.SeriesCollection.Add(worksheet.Range["A1:D6"], RowCol.Columns, true, true);

IAxis category_axis = shape.Chart.Axes.Item(AxisType.Category);
IAxis value_axis = shape.Chart.Axes.Item(AxisType.Value);
value_axis.DisplayUnit = DisplayUnit.Hundreds;
value_axis.HasDisplayUnitLabel = true;
value_axis.DisplayUnitLabel.Font.Color.RGB = Color.Green;
value_axis.DisplayUnitLabel.Font.Italic = true;
value_axis.DisplayUnitLabel.Format.Fill.Color.RGB = Color.Pink;
value_axis.DisplayUnitLabel.Format.Line.Color.RGB = Color.Red;

Tick labels

While configuring the axis of a chart, you can also set the position and layout of the tick-mark labels as per your choice using the TickLabelPosition propertyTickLabels property, TickLabelSpacing propertyTickLabelSpacingIsAuto property and TickMarkSpacing property of the IAxis interface.

Refer to the following example code to configure the tick mark label's position and layout.

C#
Copy Code
IShape shape = worksheet.Shapes.AddChart(ChartType.ColumnClustered, 200, 100, 300, 300);
worksheet.Range["A1:D6"].Value = new object[,]
{
    {null, "S1", "S2", "S3"},
    {"Item1", 10, 25, 25},
    {"Item2", -51, -36, 27},
    {"Item3", 52, -85, -30},
    {"Item4", 22, 65, 65},
    {"Item5", 23, 69, 69}
};
shape.Chart.SeriesCollection.Add(worksheet.Range["A1:D6"], RowCol.Columns, true, true);

IAxis category_axis = shape.Chart.Axes.Item(AxisType.Category);
IAxis value_axis = shape.Chart.Axes.Item(AxisType.Value);

//tick-mark labels' fill will be green according to axis's format.
category_axis.Format.Fill.Color.RGB = Color.Green;

category_axis.TickLabelPosition = TickLabelPosition.NextToAxis;
category_axis.TickLabelSpacing = 2;
category_axis.TickLabels.Font.Color.RGB = Color.Red;
category_axis.TickLabels.Font.Italic = true;
category_axis.TickLabels.NumberFormat = "#,##0.00";
category_axis.TickLabels.Offset = 100;